#
#        Python GUI - Check Boxes - Swing
#

import javax.swing as swing
from GCheckBoxes import CheckBox as GCheckBox
from StdFonts import system_font
from JHacks import *
from Controls import to_html,from_html,_j_ActionCallback

class CheckBox(GCheckBox):
    
    def __init__(self, title="Button", font=system_font, **kwds):
        self._just=kwds.get("just","left")
        self._title=title
        self._j_obj=swing.JCheckBox(to_html(title,self._just))
        
        self._actioncallback=_j_ActionCallback(self)
        self._j_obj.addActionListener(self._actioncallback)
        
        GCheckBox.__init__(self,title=title,font=font,**kwds)
    
    def activate(self):
        self._j_obj.doClick(100)
    
    def trigger(self):
        if not self.auto_toggle:
            #No support for auto-toggle in Swing, so we do it manually.
            self._j_obj.setSelected(not self._j_obj.isSelected())
    
        self.do_action()
    
    def set_on(self,on):
        self._j_obj.setSelected(on)
    
    def get_on(self):
        return self._j_obj.isSelected()
    
    def set_title(self,title):
        self._title=title
        self._j_obj.setText(to_html(title,self._just))
    
    def get_title(self):
        return self._j_obj.getText()
    
    def get_just(self):
        return self._just
    
    def set_just(self,just):
        self._just=just
        self._j_obj.setText(to_html(self._title,self._just))
    
    

